package ModelLayer;
import java.util.*;

/**
 * Write a description of class Dvd here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Dvd
{
    private long id;
    private String title;
    private String artist;
    private String publicationDate;
    private String description;
    private ArrayList<Copy> copies;
     
    /**
     * Constructor for objects of class Dvd
     */
    public Dvd(long id, String title, String artist, String publicationDate, String description)
    {
        // initialise instance variables
       this.id = id;
       this.title = title;
       this.artist = artist;
       this.publicationDate = publicationDate;
       this.description = description;
       copies=new ArrayList<>();
    }

    public Copy availableCopy()
    {        
        for(Copy copy : copies)
        {
            if(copy.getReturned()==true) { copy.setReturned(false); return copy; }
        }
        
        return null;
    }
    
    public boolean changeState(long idP, long idD, String serialNo)
    {
        for(Copy copy : copies )
            if(copy.getSerialNumber().equals(serialNo))
            {
                if(copy.getReturned()==false) copy.setReturned(true);
                else return false;
                
                return true;
            }
        
        return false;
    }
    
    public void createCopy(String serialNumber, double purchasePrice) {  copies.add(new Copy(serialNumber, purchasePrice));   }
    
    public ArrayList<Copy> getCopies()  { return copies; }
    
    public long getId()  { return id; }    
    public String getTitle() {  return title;  }
    public String getArtist() {  return artist;  }
    public String getPublicationDate() {  return publicationDate;  }
    public String getDescription() {  return description;  }
    
    public void setId(long id) { this.id = id; }
    public void setTitle(String title) { this.title = title; }
    public void setArtist(String artist) { this.artist = artist; }
    public void setpublicationDate(String publicationDate) { this.publicationDate = publicationDate; }
    public void setDescription(String description) { this.description = description; }
    
}
